using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace Commonplace.Domain
{
    public class License
    {
        string _data;
        string _name;

        public string Data { get { return _data; } }
        public string Name { get { return _name; } }

        public License(string data)
        {
            _data = data;
            Parse();
        }

        private void Parse()
        {
            //data is:  blah|blah|description
            //non-license data is ones without pipes

            string pattern = @".*\|(?<name>[^\|]+)";
            Match m = Regex.Match(_data, pattern);
            if (true == m.Groups["name"].Success)
                _name = m.Groups["name"].Value;
            else
                _name = _data;

        }

        public override string ToString()
        {
            return Name;
        }

        public static License None
        {
            get
            {
                License l = new License("");
                l._name = "None";
                l._data = string.Empty;

                return l;
            }
        }

    }
}
